package cn.iocoder.yudao.module.erp.dal.mysql.purpurchaseorder;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purpurchaseorder.vo.PurPurchaseOrderPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purpurchaseorder.PurPurchaseOrderDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * ERP 采购单 Mapper
 *
 */
@Mapper
public interface PurPurchaseOrderMapper extends BaseMapperX<PurPurchaseOrderDO> {

    default PageResult<PurPurchaseOrderDO> selectPage(PurPurchaseOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurPurchaseOrderDO>()
                .eqIfPresent(PurPurchaseOrderDO::getPurchaseOrderId, reqVO.getPurchaseOrderId())
                .eqIfPresent(PurPurchaseOrderDO::getIntegrateId, reqVO.getIntegrateId())
                .eqIfPresent(PurPurchaseOrderDO::getIsMainOrder, reqVO.getIsMainOrder())
                .eqIfPresent(PurPurchaseOrderDO::getIsFinished, reqVO.getIsFinished())
                .eqIfPresent(PurPurchaseOrderDO::getMainOrderId, reqVO.getMainOrderId())
                .betweenIfPresent(PurPurchaseOrderDO::getOrderTime, reqVO.getOrderTime())
                .eqIfPresent(PurPurchaseOrderDO::getSupplierId, reqVO.getSupplierId())
                .eqIfPresent(PurPurchaseOrderDO::getTotalPrice, reqVO.getTotalPrice())
                .eqIfPresent(PurPurchaseOrderDO::getOrderIntegrateId, reqVO.getOrderIntegrateId())
                .eqIfPresent(PurPurchaseOrderDO::getRemark, reqVO.getRemark())
                .eqIfPresent(PurPurchaseOrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PurPurchaseOrderDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(PurPurchaseOrderDO::getCreator, reqVO.getCreator())
                .betweenIfPresent(PurPurchaseOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurPurchaseOrderDO::getCreateTime));
    }
    default PurPurchaseOrderDO getPurPurchaseOrderByPurchaseOrderId(String purPurchaseOrderId) {
         return selectOne(PurPurchaseOrderDO::getPurchaseOrderId, purPurchaseOrderId);
    }

    List<PurPurchaseOrderDO> selectListByIds(@Param("ids")List<Integer> purchaseOrderIds);

    default  List<PurPurchaseOrderDO> getListByIds(List<String> ids){
        return selectList(PurPurchaseOrderDO::getId,ids);
        }

    default PurPurchaseOrderDO selectByNo(String no){
        return selectOne(PurPurchaseOrderDO::getPurchaseOrderId,no);
    }

    default List<PurPurchaseOrderDO> getPurPurchaseOrderByOrderIntegrateId(String orderIntegrateId){
        return  selectList(PurPurchaseOrderDO:: getOrderIntegrateId,orderIntegrateId);
    }
}